/**
 * HMI 批量更新组件类型定义
 */

export interface HmiTableRow {
  [key: string]: any;
  _index: number;
  newValue: any;
  _originalValue?: any;
  _hasChanged?: boolean;
}

export interface HmiColumnConfig {
  key: string;
  label: string;
  type: "enum" | "number" | "string" | "boolean";
  index?: number;
  width?: number;
  minWidth?: number;
  editable?: boolean;
  required?: boolean;
  // 枚举类型配置
  enumOptions?: Array<{ Value: any; Desc: string }>;
  // 数字类型配置
  min?: number;
  max?: number;
  step?: number;
  fix?: number;
  // 字符串类型配置
  maxLength?: number;
  pattern?: RegExp;
}

export interface HmiBatchUpdateConfig {
  apiPath: string;
  updateApi?: string;
  idKey: string;
  valueKey: string;
  enumKey?: string;
  updateIdKey: string;
  updateValueKey: string;
  updateBodyKey?: string[];
  updateBodyConfig?: UpdateBodyConfig;
  columns: HmiColumnConfig[];
  showSettingZone?: boolean;
  showAutoSetButton?: boolean;
  autoSetApi?: string;
  pagination?: {
    pageSize: number;
    showSizeChanger?: boolean;
  };
  group?: string;
  orderByKey?: string;
  enableAutoRefresh?: boolean;
}

export interface UpdateBodyConfig {
  type: string;
  olflag: number;
}

export interface ChangeRecord {
  id: string | number;
  oldValue: any;
  newValue: any;
  column: string;
}

export interface HmiBatchUpdateEmits {
  "update:loading": [loading: boolean];
  "data-changed": [changes: ChangeRecord[]];
  "save-success": [data: any];
  "save-error": [error: Error];
}

export interface HmiBatchUpdateProps {
  config: HmiBatchUpdateConfig;
  loading?: boolean;
  readonly?: boolean;
  showToolbar?: boolean;
  showExport?: boolean;
}
